package com.example.heraclitoapp;

//import java.util.List;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class SelectedAdapter extends ArrayAdapter {

	// used to keep selected position in ListView
	private int selectedPos1 = -1; // init value for not-selected
	private int selectedPos2 = -1;

	public SelectedAdapter(Context context, int textViewResourceId,
			String[] objects) {
		super(context, textViewResourceId, objects);
	}

	public void setSelectedPosition1(int pos) {
		selectedPos1 = pos;
		// inform the view of this change
		notifyDataSetChanged();
	}

	public void setSelectedPosition2(int pos) {
		selectedPos2 = pos;
		// inform the view of this change
		notifyDataSetChanged();
	}

	public int getSelectedPosition1() {
		return selectedPos1;
	}

	public int getSelectedPosition2() {
		return selectedPos2;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;

		// only inflate the view if it's null
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) this.getContext()
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.selected_row, null);
		}

		// get text view
		TextView label = (TextView) v.findViewById(R.id.txtExample);
		//Typeface tf = Typeface.createFromAsset(getContext().getAssets(),
          //      "DejaVuSansMono.TTF");
		//label.setTypeface(tf);
		
		// change the row color based on selected state
		if ((selectedPos1 == position && selectedPos1 != 0)
				|| (selectedPos2 == position && selectedPos2 != 0)) {
			label.setBackgroundColor(Color.parseColor("#6633b5e5"));
		} else {
			label.setBackgroundColor(Color.TRANSPARENT);
		}

		label.setText(this.getItem(position).toString());
		/*
		 * // to use something other than .toString() MyClass myobj =
		 * (MyClass)this.getItem(position);
		 * label.setText(myobj.myReturnsString());
		 */
		return (v);
	}

}